package com.suray.basic.wcs.plc.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.suray.basic.wcs.plc.entity.LifterCodeDB;
import com.suray.basic.wcs.plc.mapper.LifterCodeDBMapper;
import com.suray.basic.wcs.plc.service.ILifterCodeDBService;
import org.springframework.stereotype.Service;

import java.util.List;
@Service
public class LifterCodeDBServiceImpl extends ServiceImpl<LifterCodeDBMapper, LifterCodeDB>
        implements ILifterCodeDBService {
    /**
     * 根据条件分页查询异常码列表
     *
     * @param forkLifterErrorInfoDB 异常码信息
     * @return 异常码信息集合信息
     */
    public List<LifterCodeDB> selectCodeList(LifterCodeDB forkLifterErrorInfoDB) {
        LambdaQueryWrapper<LifterCodeDB> queryWrapper = new LambdaQueryWrapper();
        if (forkLifterErrorInfoDB.getMessage() != null) {
            queryWrapper.eq(LifterCodeDB::getMessage, forkLifterErrorInfoDB.getMessage());
        }
        return baseMapper.selectList(queryWrapper);
    }
    /**
     * 通过故障码查询故障描述
     *
     * @param code
     * @return
     */
    public String getCodeDescByError(Integer code) {
        if (code == null || code == 0) {
            return "无故障";
        }
        QueryWrapper<LifterCodeDB> queryWrapper = new QueryWrapper<>();
        queryWrapper.lambda().eq(LifterCodeDB::getCode, code);
        LifterCodeDB errorInfoDB = this.getOne(queryWrapper, false);
        if (errorInfoDB != null) {
            return errorInfoDB.getMessage();
        } else {
            return "故障码:" + code + "无描述";
        }
    }
}
